package org.beetl.core.util;

import java.lang.reflect.Modifier;

public class JavaVersion {
	public static final int JAVA_MAJOR_VERSION;
	static {
		int majorVersion;
		try {
			String version = System.getProperty("java.specification.version");
			if (version.startsWith("1.")) {
				version = version.substring(2);
			}
			majorVersion = Integer.parseInt(version);
		} catch (Throwable ignored) {
			majorVersion = 8;
		}
		JAVA_MAJOR_VERSION = majorVersion;
	}
	public static boolean supportRecord(){
		return JAVA_MAJOR_VERSION>=16;
	}

	public static boolean isRecordClass(Class c){
		//考虑兼容JDK8,这种判断相比于c.isRecord 不准确,但在JAVA8下能编译通过
		return c.getSuperclass().getName().equals("java.lang.Record")&&(c.getModifiers() & Modifier.FINAL) != 0;
	}
}
